<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mpChannel-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">渠道名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">渠道编码：</label>
				<div class="col-sm-8">
					<input id="code" name="code" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">渠道秘钥 ：</label>
				<div class="col-sm-8">
					<input id="secretKey" name="secretKey" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">渠道支付方法-费率：</label>
				<div class="col-sm-8">
					<input id="payRate" name="payRate" class="form-control" type="text" placeholder="0.0001" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户支付方法-费率：</label>
				<div class="col-sm-8">
					<input id="merchantPayRate" name="merchantPayRate" class="form-control" type="text" placeholder="0.0001" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">渠道支付方法-支付限额(元)：</label>
				<div class="col-sm-3" style="display:inline">
					<input id="payLimitLeft" name="payLimitLeft" class="form-control" type="text"  required>
				</div>
				<div style="display:inline;margin-left: -1%;margin-top: 1%;position: absolute;">
					<span>—</span>
				</div>
				<div class="col-sm-3">
					<input id="payLimitRight" name="payLimitRight" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">方法类名：</label>
				<div class="col-sm-8">
					<input id="className" name="className" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">接口地址 ：</label>
				<div class="col-sm-8">
					<input id="reqUrl" name="reqUrl" class="form-control" type="text" placeholder="http://www.xxx.com或https://www.xxx.com" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">代付优先级：</label>
				<div class="col-sm-8">
					<input id="withdrawalLevel" name="withdrawalLevel" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">代付手续费(元)：</label>
				<div class="col-sm-8">
					<input id="withdrawalFee" name="withdrawalFee" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商户代付手续费(元)：</label>
				<div class="col-sm-8">
					<input id="mchWithdrawalFee" name="mchWithdrawalFee" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">代付限额(元)：</label>
				<div class="col-sm-3" style="display:inline">
					<input id="withdrawalLimtLeft" name="withdrawalLimtLeft" class="form-control" type="text"  required>
				</div>
				<div style="display:inline;margin-left: -1%;margin-top: 1%;position: absolute;">
					<span>—</span>
				</div>
				<div class="col-sm-3">
					<input id="withdrawalLimtRight" name="withdrawalLimtRight" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">联系人姓名：</label>
				<div class="col-sm-8">
					<input id="contactName" name="contactName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">联系人手机：</label>
				<div class="col-sm-8">
					<input id="contactPhone" name="contactPhone" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">联系人邮箱：</label>
				<div class="col-sm-8">
					<input id="contactEmail" name="contactEmail" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">渠道状态：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="false" class="onoffswitch-checkbox" id="status" name="status">
						<label class="onoffswitch-label" for="status">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">代付内扣：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="false" class="onoffswitch-checkbox" id="withdrawalInner" name="withdrawalInner">
						<label class="onoffswitch-label" for="withdrawalInner">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 control-label">支付类型：</label>
				<div class="col-xs-9">
					<label th:each="pay:${pays}" class="check-box">
						<input name="payIds" type="checkbox" th:value="${pay.id}" th:text="${pay.name}">
					</label>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "channel/channelInfo";
		/* 代付优先级  默认值*/
		$("#withdrawalLevel").val(1);
		/*表单验证*/
        $.validator.addMethod("regex",function (value, element, params) {
            var exp = new RegExp(params);
            return exp.test(value);
        },"请输入数字(可保留两位小数)");
	 	$.validator.addMethod("mobile",function (value, element, params) {
	 	    if (value !== "" && value !== null) {
                var exp_mobile = new RegExp(params);
                return exp_mobile.test(value);
			}else {
	 	        return true;
			}
	 	},"请输入正确的手机号码");
        $.validator.addMethod("emmail",function (value, element, params) {
            if (value !== "" && value !== null) {
                var exp_email = new RegExp(params);
                return exp_email.test(value);
            }else {
                return true;
            }
        },"请输入正确的邮箱");
        $.validator.addMethod("number",function (value, element, params) {
            var exp_email = new RegExp(params);
            return exp_email.test(value);
        },"请输入正整数");
        $.validator.addMethod("regex2",function (value, element, params) {
            var exp = new RegExp(params);
            return exp.test(value);
        },"小于1(可保留四位小数)");
		$("#form-mpChannel-add").validate({
            rules:{
                name:{
                    remote: {
                        url:prefix + "/checkChannelNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "name":function () {
                                return $.common.trim($("#name").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                className:{
                    remote: {
                        url:prefix + "/checkClassNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "className":function () {
                                return $.common.trim($("#className").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                contactPhone:{
                    mobile: "^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$"
				},
                contactEmail:{
                    emmail:"^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$"
				},
				withdrawalLevel:{
                    number:"^[0-9]*[1-9][0-9]*$"
				},
                withdrawalFee:{
                    regex:"^[0-9]+(.[0-9]{2}|.[0-9]{1})?$"
				},
                mchWithdrawalFee:{
                    regex:"^[0-9]+(.[0-9]{2}|.[0-9]{1})?$"
				},
                withdrawalLimt: {
                    regex:"^[0-9]+(.[0-9]{2}|.[0-9]{1})?$"
                },
                mchWithdrawalLimt: {
                    regex:"^[0-9]+(.[0-9]{2}|.[0-9]{1})?$"
                },
                reqUrl: {
                	url:true
				},
                payRate:{
                    regex2:"^[0]+(.[0-9]{4}|.[0-9]{3}|.[0-9]{2}|.[0-9]{1})?$"
                },
                merchantPayRate:{
                    regex2:"^[0]+(.[0-9]{4}|.[0-9]{3}|.[0-9]{2}|.[0-9]{1})?$"
				},
                payLimitLeft:{
                    regex:"^[0-9]+(.[0-9]{2}|.[0-9]{1})?$"
                },
                payLimitRight:{
                    regex:"^[0-9]+(.[0-9]{2}|.[0-9]{1})?$"
                }
            },
            messages: {
                "name": {
                    remote: "渠道类型已经存在"
                },
                "className": {
                    remote: "类名已经存在"
                }
            },
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
                var data = $("#form-mpChannel-add").serializeArray();
                var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
                var withdrawalInner = $("input[id='withdrawalInner']").is(':checked') == true ? 0 : 1;
                if (status != 0){
                    data.push({"name": "status", "value": status});
                    if (withdrawalInner != 0){
                        data.push({"name": "withdrawalInner", "value": withdrawalInner});
                    }else {
                        data[17].value = withdrawalInner;
                    }
                } else {
                    data[17].value = status;
                    if (withdrawalInner != 0){
                        data.push({"name": "withdrawalInner", "value": withdrawalInner});
                    } else {
                        data[18].value = withdrawalInner;
                    }
                }
                // 支付限额左
                data[5].value = new Decimal(data[5].value).mul(new Decimal(100));
                // 支付限额右
                data[6].value = new Decimal(data[6].value).mul(new Decimal(100));
                // 代付手续费
				data[10].value = new Decimal(data[10].value).mul(new Decimal(100));
                // 商户代付手续费
                data[11].value = new Decimal(data[11].value).mul(new Decimal(100));
                // 代付限额左
                data[12].value = new Decimal(data[12].value).mul(new Decimal(100));
                // 代付限额右
                data[13].value = new Decimal(data[13].value).mul(new Decimal(100));
                $.operate.save(prefix + "/add", data);
	        }
	    }
	</script>
</body>
</html>
